package jdbc;

import java.sql.*;

public class JDBCDemo_ResultSet_Demo2 {
    public static void main(String[] args) throws SQLException {
        //1.注册驱动.....
        //2.获取连接
        Connection connection = DriverManager.
                getConnection("jdbc:mysql:///学生库", "root", "mysql");
        //定义sql语句
        String sql = "select * from account";
        //获取sql执行对象
        Statement statement = connection.createStatement();
        //执行sql语句
        ResultSet resultSet = statement.executeQuery(sql);
        //6.遍历resultSet中使用数据
        //6.1.resultSet.next()光标向下移动一行,并且判断是否有数据
        while (resultSet.next()){
            //6.2获取数据 resultSet.getXxx();
            String sno = resultSet.getString(1);
            String name = resultSet.getString(2);
            String sex = resultSet.getString(3);
            System.out.println(sno);
            System.out.println(name);
            System.out.println(sex);
            System.out.println("-------------------------------");
        }
        resultSet.close();
        statement.close();
        connection.close();
    }
}
